﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>销售信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script src="~/js/layui/layui.js"></script>
    <script src="~/js/sysweb/planjs.js"></script>

</head>
<body>
    <div class="layui-fluid">
      <div id="bDiv">
      </div>
       <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" placeholder="开始日期" name="sDate" id="sDate" style="margin-right:15px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" placeholder="结束日期" name="eDate" id="eDate" style="margin-right:15px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="cSOCode" placeholder="销售订单号" autocomplete="off" class="layui-input" id="cSOCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="customName" placeholder="客户名称" autocomplete="off" class="layui-input" id="customName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="proCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="cPersonName" placeholder="业务员" autocomplete="off" class="layui-input" id="cPersonName">
                            </div>

                        </form>
                        
                    </div>

                    <div class="layui-card-body layui-table-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var cData = new Array();
    $(function () {
        $("input[ name='sDate']").val(getDate(-5));
        $("input[ name='eDate']").val(getDate(0));
        BannerData("selectWin", "bDiv");
        loadData();
    })
    /*
     *加载销售计划数据
     * */
    function loadData() {
        list = new Array();//关闭弹出页面后会刷新列表，但list还是之前勾选的行没有清空，在这清空一下
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                    { type: 'checkbox' }
                    , { field: 'erpOrder', title: '销售单号', width: 130 }
                    , { field: 'cuName', title: '客户', width: 130 }
                    , { field: 'cPersonName', title: '业务员', width: 90 }
                    , { field: 'fDate', title: '交货日期', width: 120 }
                    , { field: 'proCode', title: '存货编码', width: 130 }
                    , { field: 'proName', title: '存货名称', width: 160 }
                    , { field: 'spec', title: '规格', width: 110 }
                    , { field: 'cDefine22', title: '材质', width: 110 }
                    , { field: 'number', title: '订单数量', width: 90 }
                    , { field: 'realNum', title: '可用数量', width: 90 }
                    , { field: 'doNum', title: '计划生产', width: 90 }
                    , { field: 'cComUnitName', title: '主计量', width: 70 }
                    , { field: 'memo', title: '备注', width: 90 }

                ]], done: function (res, curr, count) {
                    $.each(res['data'], function (i, j) {
                        // if (j['isUsed'] == "1") {
                        //    TableRowColor('layui-table-main', i, '#aaceec');
                        // } 
                    });
                }
                , url: "../Plan/getDataList?dataType=sale&condition=" + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
                , limits: [20, 30, 50]
                , limit: 50 //每页默认显示的数量
            });
            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var checkStatus = table.checkStatus('list');
                var select = new Array();
                for (var i = 0; i < checkStatus.data.length; i++) {
                    select.push(checkStatus.data[i]);

                }
                cData = select;
            });

        });
    }

    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#sDate',
            trigger: 'click',
            type: 'date',
            format: 'yyyy-MM-dd',
            max: nowTime,
            btns: ['clear', 'confirm'],
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date; //最大时间为结束时间的开始值
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#eDate',
            trigger: 'click',
            type: 'date',
            max: 4073558400000,
            format: 'yyyy-MM-dd',
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = { 'date': curDate.getDate(), 'month': curDate.getMonth() + 1, 'year': curDate.getFullYear() };
                }
                start.config.max = date;//最小时间为开始时间的最大值
                start.config.max.month = date.month - 1;
            }
        })
    })
    var single="1";
    function Confirm() {
        if (cData.length < 1) {
            layer.msg("您没有选择任何数据"); return;
        } else {
            if (single == "1" && cData.length > 1) {
                layer.msg("请选择一条数据"); return;
            } 
            else {
                // if (Number(cData[0]["doNum"]) > 0) {
                //     layer.msg("该销售订单已创建计划，不允许再次创建"); return;
                // }

                parent.getSaleOrderPar(cData); //这是父页面函数
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        }
    }


</script>